package org.hank.demoproject

import android.util.Log
import com.solab.iso8583.IsoMessage
import com.solab.iso8583.IsoType
import com.solab.iso8583.MessageFactory
import com.solab.iso8583.parse.ConfigParser
import org.hank.utils.spdh.SpdhUtils
import org.junit.Test

import org.junit.Assert.*

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun test() {
        var message = IsoMessage()
        message.type = 0x0200
        message.setValue(3, "000000", IsoType.NUMERIC, 6)
        message.setValue(4, "50.33", IsoType.AMOUNT, 12)
        message.setValue(7, "1211155904", IsoType.DATE10, 10)
        message.setValue(11, "444382", IsoType.NUMERIC, 6)
        message.setValue(12, "155852", IsoType.TIME, 6)
        message.setValue(13, "1211", IsoType.DATE4, 4)
        message.setValue(17, "1211", IsoType.DATE4, 4)
        message.setValue(18, "5541", IsoType.NUMERIC, 4)
        message.setValue(22, "0510", IsoType.NUMERIC, 4)
        message.setValue(25, "01", IsoType.NUMERIC, 2)
        message.setValue(32, "0000000100", IsoType.LLVAR, 10)
        message.setValue(35, "549532******7814=******************", IsoType.LLVAR, 37)
        message.setValue(37, "034615444382", IsoType.NUMERIC, 12)
        message.setValue(41, "HP640285        ", IsoType.ALPHA, 16)
        message.setValue(43, "Brodske - Breclav (D2)Kuty         SK SK", IsoType.ALPHA, 40)
        message.setValue(48, "642100             00000000", IsoType.LLLVAR, 30)
        message.setValue(49, "978", IsoType.NUMERIC, 3)
        message.setValue(60, "0100DVL1+0000000", IsoType.LLLVAR, 19)
        message.setValue(61, "        000        ", IsoType.LLLVAR, 22)
        message.setValue(
            63,
            "& 0000900464! 0400020                   Y ! B200158 7FF9000080000000800054F85296EE7BA68300000000500000000000000039000221703978201211000AC71C9900180111A74003040000000000000000000000FF0000000000000000000000000000! B300080 4F0000000000E0F8C8000000000000002200024403020007A0000000041010000000000000000000! B400020 05151001440302    0 ! C000026         908 85            ! C400012 000000000082! P500016 \\RI3200518714\\00! CH00040                                      1  ",
            IsoType.LLLVAR,
            999
        )
        message.setValue(124, "009382000000", IsoType.NUMERIC, 12)
        message.setValue(125, "012          1 ", IsoType.NUMERIC, 15)
        message.isoHeader = "ISO026000070"

        System.out.println("packMsg" + String(message.writeData()))

        var msgReal =
            "ISO0260000700200B238C48128A1801A0000000000000018000000000000005000121115590444438215585212111211554105100110000000010035549532******7814=******************034615444382HP640285        Brodske - Breclav (D2)Kuty         SK SK027642100             000000009780160100DVL1+0000000019        000        464& 0000900464! 0400020                   Y ! B200158 7FF9000080000000800054F85296EE7BA68300000000500000000000000039000221703978201211000AC71C9900180111A74003040000000000000000000000FF0000000000000000000000000000! B300080 4F0000000000E0F8C8000000000000002200024403020007A0000000041010000000000000000000! B400020 05151001440302    0 ! C000026         908 85            ! C400012 000000000082! P500016 \\RI3200518714\\00! CH00040                                      1  009382000000012          1 "
        var factory = ConfigParser.createDefault()
        var unpackMessage = factory.parseMessage(msgReal.toByteArray(),12)
        System.out.println("unpackMsg" + String(unpackMessage.writeData()))
    }

    @Test
    fun testSPDHUtil(){
//        9.63TCT00001              150804161202FO00150000[1C]B85[1C]D0[1C]P1[1C]S000599[1C]d111         [1C]e00[1C]h0010170821[1C]q;417666222001
        System.out.println(SpdhUtils.str2Header("9.63TCT00001              150804161202FO00150000").toString())
        System.out.println(SpdhUtils.str2Fields("[1C]B85[1C]D0[1C]P1[1C]S000599[1C]d111         [1C]e00[1C]h0010170821[1C]q;417666222001").toString())
    }
}